!-------------------------------------------------------------LICENSE--------------------------------------------------------------!
!                                                                                                                                  !
!The MAP code is written in Fortran language for magnetohydrodynamics (MHD) calculation with the adaptive mesh refinement (AMR)    !
!and Message Passing Interface (MPI) parallelization.                                                                              !
!                                                                                                                                  !
!Copyright (C) 2012                                                                                                                !
!Ronglin Jiang                                                                                                                     !
!rljiang@ssc.net.cn                                                                                                                !
!585 Guoshoujing Road. Pudong, Shanghai, P.R.C. 201203                                                                             !
!                                                                                                                                  !
!This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License         !
!as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.             !
!                                                                                                                                  !
!This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of    !
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.                        !
!                                                                                                                                  !
!You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software     !
!Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                                                   !
!                                                                                                                                  !
!-------------------------------------------------------------LICENSE--------------------------------------------------------------!

recursive subroutine block_info (current)

   use parameters
   use block_define

   implicit none

   type (block), pointer, intent(inout) :: current
   character(10), dimension(n_neighs, n_levels) :: neighbors
   character(2), dimension(n_levels) :: level_flag
   integer(4) :: nx_t, i_block, i_neigh, i_level
   type (block), pointer :: child

!----------------------------------------------------------------------------------------------------------------------------------------------|
   nx_t = size (current%x)

   level_flag = ' '
   if (current%lv .ge. 1) then
      level_flag(current%lv) = '*'
      if (current%neigh_lv(1) .eq. 0) level_flag(current%lv) = '*l'
      if (current%neigh_lv(2) .eq. 0) level_flag(current%lv) = '*r'
   endif

   do i_level = 1, n_levels
   do i_neigh = 1, n_neighs
      if (associated (current%neigh(i_neigh, i_level)%pblock)) then
         neighbors(i_neigh, i_level) = current%neigh(i_neigh, i_level)%pblock%id
      else
         neighbors(i_neigh, i_level) = '   NULL   '
      endif
   enddo
   enddo

   write (*, *) '|----------------------------------------------------------------------|'
   write (*, *) ' Block ID: ', current%id
   write (*, *) ' Block LEVEL: ', current%lv
   write (*, *) ' X range: ', real(current%x(1 + ng)), real(current%x(nx_t - ng))
   write (*, *) ' Ghost points (left): ', real(current%x(1:ng))
   write (*, *) ' Ghost points (right): ', real(current%x(nx_t-ng+1:nx_t))
   write (*, *) ' Number of children: ', current%nc
   write (*, *) ' IDs of children: ', (current%child(i_block)%id, ' ', i_block = 1, current%nc)
   write (*, *) ' Neighbors id (left, right), LEVEL'
   do i_level = n_levels, 1, -1
      write (*, *) ' ', (neighbors(i_neigh, i_level), ' ', i_neigh = 1, n_neighs), i_level, level_flag(i_level)
   enddo
   write (*, *) ' Max LEVEL of neighbors(left, right): ', current%neigh_lv
   write (*, *) ' Total number of blocks: ', n_blocks
   write (*, *) '|----------------------------------------------------------------------|'

   pause

   do i_block = 1, current%nc
      child => current%child(i_block)
      if (associated (child)) call block_info (child)
   enddo

   return
end subroutine block_info
